package com.cykj.consumer;

import com.cykj.mapper.OrderMapper;
import com.cykj.pojo2.CyOrder;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic="cancel-order",consumerGroup ="${rocketmq.consumer.cancel-group}")
public class CancelOrderConsumer implements RocketMQListener<CyOrder> {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @Override
    public void onMessage(CyOrder order) {
        System.out.println(order);
        System.out.println("jishou");
        CyOrder o=orderMapper.getOrderById(order.getId());
        System.out.println(o);
        if(o.getPayState()!=1){
            System.out.println("超时未支付，取消订单");
            orderMapper.updateOrder(o.getId(),1);
            redisTemplate.opsForValue().increment("stock:"+o.getGoodId(),o.getBuyCount());
        }

    }
}
